package Practice03;

public class Counter {
    private int  count;
    private int maxValue;
    public Counter(int count, int maxValue){
        this.count = count;
        this.maxValue = maxValue;
    }

    public void increment(){
        count++;
        if (count > maxValue){
            System.out.println("已经是最大值了");
            count = maxValue;
        }
    }
    public void decrement(){
        count--;
        if (count < 0){
            System.out.println("计数器不为负数");
            count = 0;
        }
    }
    public void setCount(int c){
        if (c <= maxValue){
            count = c;
        }else {
            System.out.println("超过设置的最大值");
        }
    }
    public void setMaxValue(double mv){
        if (mv <= Integer.MAX_VALUE){
            maxValue = (int) mv;
        }else {
            System.out.println("超过int的最大值");
        }
    }
    public int getCount(){
        return Math.min(count,maxValue);
    }
    public int getMaxValue(){
        return maxValue;
    }
}
